#include<Arkhelper.h>
using namespace std;
#ifndef NameSpaceADB
#define NameSpaceADB
namespace adb{
	void Run(const string _Command){const string _R=".\\SupportPackage.\\adb.exe "+_Command;system(_R.c_str());}
	void Openapp(const string _Package){const string _R="shell am start "+_Package;Run(_R);}
	void Closeapp(const string _Package){const string _R="shell am force-stop "+_Package;Run(_R);}
	void Tap(const POS _Pos){const string _Rcom="shell input tap "+itos(_Pos.first)+" "+itos(_Pos.second);Run(_Rcom);}
	void Getscreen(){
		Run("shell screencap -p /sdcard/XscreenX.png");Run("pull /sdcard/XscreenX.png temp/");
		system("magick identify -format \"%wx%h\" temp/XscreenX.png > size.txt") ;
		ifstream fin("temp/size.txt");
		string sResource;
		getline(fin,sResource);
		bool innum=0,two=0;
		string str1="",str2="";
		for(unsigned int i=0;i<sResource.size();i++){
			if(isdigit(sResource[i])){innum=1;}
				else {innum=0;}
			if(sResource[i]=='x'){two=1;}
			if(innum){
				if(!two){
					str1+=sResource[i];
				}
				else {
					str2+=sResource[i];
				}
			}
		}
		int w=stoi(str1),h=stoi(str2);
		if(w<h){
			magick::Rotatepic(_LeftRotate,"XscreenX.png","screen.png");
		}
		else{
			magick::Rotatepic(0,"XscreenX.png","screen.png");
		} 
		fin.close();
	}
	void Input_Text(const string _Txt){const string _Rcom="shell input text "+_Txt;Run(_Rcom);}
	void Swipe(const Data_Set _S,const int _Tim=1000){const string _R="shell input swipe "+itos(_S.P_1.first)+" "+itos(_S.P_1.second)+" "+itos(_S.P_2.first)+" "+itos(_S.P_2.second)+" "+itos(_Tim);Run(_R);}
}	
#endif
#ifndef adbFunc
#define adbFunc
void Swipe_To_Left(const int Times){
	for(int i=1;i<=Times;i++){
		adb::Swipe(_SwipeToLeft,300);
		adb::Tap(_SwipeToLeft.P_2);
	}
}
void Swipe_To_Right(const int Times){
	for(int i=1;i<=Times;i++){
		adb::Swipe(_SwipeToRight,500);
		adb::Tap(_SwipeToRight.P_2);
	}
}
bool TheSamePic(const Group_Of_Data _Pack){
	adb::Getscreen();
	magick::Getarea(_Pack.L_U,_Pack.R_D,"screen.png","Cpr.png");
	magick::Compare("Cpr.png",_Pack.Name_);
	magick::P2rgb("diff.png");
	fstream fin("temp/RGB.txt");
	string _S;getline(fin,_S);
	string The_Most="NULL";
	int Largest_=0;
	map<string,int>Mp_; 
	while(fin>>_S){
		if(_S[0]=='#')Mp_[_S]++;
		if(Mp_[_S]>=Largest_){
			Largest_=Mp_[_S];
			The_Most=_S;
		}
	}
	return The_Most==_SameCol;
}
#endif


